class ListNode{
    int val;
    ListNode next;
    public ListNode(int val){
        this.val = val;
    };
    public ListNode(int val,ListNode next){
        this.val = val;
        this.next = next;
    }

}
public class Test1 {
    public static int rob(int[] nums) {
        int length = nums.length;
        int[] dp = new int[length];
        if(nums == null || length == 0){
            return 0;
        }
        if(length == 1){
            return nums[0];
        }
        dp[0] = nums[0];
        dp[1] = Math.max(nums[0],nums[1]);
        for(int i = 2; i < length; i++){
            dp[i] = Math.max(dp[i-1],nums[i] + dp[i-2]);
        }

        return dp[length-1];
    }
    public static int rob1(int[] nums) {
        int ret = 0;
        int sum1 = 0 , sum2 = 0;
        for(int i = 0; i < nums.length; i++){
            if(i % 2 == 0){
                sum2 += nums[i];
            }else{
                sum1 += nums[i];
            }
        }

        if(sum1 > sum2){
            ret = sum1;
        } else {
            ret = sum2;
        }

        return ret;
    }

    public static void main(String[] args) {
        int[] nums = {11,242,123,342,122,176,43,63,231,44};
        System.out.println(rob(nums));
    }
    public static ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        ListNode l1 = list1;
        ListNode l2 = list2;
        ListNode ret = new ListNode(-1);
        ListNode phead = ret;
        while(l1 != null && l2 !=null){
            if(l1.val < l2.val){
                phead.next = l2;
                phead = phead.next;
                l2 = l2.next;
            }else{
                phead.next = l1;
                phead = phead.next;
                l1 = l1.next;
            }
        }
        if(l1 != null){
            phead.next = l1;
        }
        if(l2 != null){
            phead.next = l2;
        }
        return ret.next;
    }
    public static void main1(String[] args) {
        ListNode l3 = new ListNode(4,null);
        ListNode l2 = new ListNode(2,l3);
        ListNode l1 = new ListNode(1,l2);

        ListNode l6 = new ListNode(4,null);
        ListNode l5 = new ListNode(3,l1);
        ListNode l4 = new ListNode(1,l2);

        ListNode ret = mergeTwoLists(l1,l4);
    }
}